<template>
	<div v-loading="!isShow">
		<div class="zs-card-sm zs-space-bottom zs-layout-flex-row">
			<el-select v-model="biProjectCode" class="zs-select-md zs-space-right-sm" placeholder="项目名称" @change="changeProject">
				<el-option v-for="item in projectList" :key="item.biProjectCode" :label="item.projectName" :value="item.biProjectCode" />
			</el-select>
			<el-date-picker v-if="isShowDigitalMonthlyReport" class="zs-select-md zs-space-right-sm" v-model="yearmonth" type="month" placeholder="月份" value-format="YYYY-MM" :clearable="false" @change="getTableData"/>
			<el-button v-if="isShowDigitalMonthlyReport" class="zs-btn-plain" @click="getTableData"> 查询 </el-button>
			<span class="zs-layout-flex-row zs-layout-justify-end zs-layout-grow">
				<el-button v-for="(tab, index) in groupList" :key="index" class="" :class="{'zs-btn-primary': tabIndex == index, 'zs-btn-info' : tabIndex != index}" @click="changeTab(index)">{{ tab.name }}</el-button>
			</span>
		</div>
		<el-scrollbar class="db-content-height" v-if="isShow && isShowDashboard">
			<div class="db-content-cards">
				<!-- 基本信息 暂时不要了 -->
				<!-- <BaseInfo :biProjectCode="biProjectCode" :projectCode="projectCode" :permi="tabPermi"></BaseInfo> -->
				<template v-for="card in resourceList" :key="card.permissionKey">
					<!-- 销售额 -->
					<SalesVolume v-if="card.permissionKey == 'p_btn_901_jingyingxiangmu_xiangqing_xiaoshoue'"  :permi="card.permissionKey" :hideList="hideList" :biProjectCode="biProjectCode" :updateDate="updateDate"></SalesVolume>
					<!-- 客流量 -->
					<PassengerFlow v-if="card.permissionKey == 'p_btn_901_jingyingxiangmu_xiangqing_keliu'" :permi="card.permissionKey" :hideList="hideList" :biProjectCode="biProjectCode" :updateDate="updateDate"></PassengerFlow>
					<!-- 房态图 -->
					<HouseCard v-if="card.permissionKey == 'p_btn_901_jingyingxiangmu_xiangqing_fangtaitu'" :permi="card.permissionKey" :hideList="hideList" :biProjectCode="biProjectCode" :updateDate="updateDate"></HouseCard>
					<!-- 品牌分析 -->
					<BrandAnalysis v-if="card.permissionKey == 'p_btn_901_jingyingxiangmu_xiangqing_pinpaifenxi'" :permi="card.permissionKey" :hideList="hideList" :biProjectCode="biProjectCode"></BrandAnalysis>
					<!-- 工单监控 -->
					<WorkerOrder v-if="card.permissionKey == 'p_btn_901_jingyingxiangmu_xiangqing_gdjk'" :permi="card.permissionKey" :hideList="hideList" :projectCode="projectCode" :updateDate="updateDate"> </WorkerOrder>
					<!-- 出租情况 -->
					<RentalSituation v-if="card.permissionKey == 'p_btn_901_jingyingxiangmu_xiangqing_chuzu'" :title="'商铺'" :permi="card.permissionKey" :hideList="hideList" :biProjectCode="biProjectCode" :updateDate="updateDate"></RentalSituation>
					<!-- 租赁分析-中岛位 -->
					<LeaseAnalysis v-if="card.permissionKey == 'p_btn_901_jingyingshangye_zhongdaoweichuzu'" :permi="card.permissionKey" leaseType="zhongdao" :hideList="hideList" :biProjectCode="biProjectCode" :biProjectName="biProjectName" :updateDate="updateDate"></LeaseAnalysis>
					<!-- 租赁分析-场地 -->
					<LeaseAnalysis v-if="card.permissionKey == 'p_btn_901_jingyingshangye_changdichuzu'" :permi="card.permissionKey" leaseType="place" :hideList="hideList" :biProjectCode="biProjectCode" :biProjectName="biProjectName" :updateDate="updateDate"></LeaseAnalysis>
					<!-- 租赁分析-库房 -->
					<LeaseAnalysis v-if="card.permissionKey == 'p_btn_901_jingyingshangye_kufangchuzu'" :permi="card.permissionKey" leaseType="warehouse" :hideList="hideList" :biProjectCode="biProjectCode" :biProjectName="biProjectName" :updateDate="updateDate"></LeaseAnalysis>
					<!-- 租赁分析-广告 -->
					<LeaseAnalysis v-if="card.permissionKey == 'p_btn_901_jingyingshangye_guanggaoweichuzu'" :permi="card.permissionKey" leaseType="ad" :hideList="hideList" :biProjectCode="biProjectCode" :biProjectName="biProjectName" :updateDate="updateDate"></LeaseAnalysis>
					<!--新签面积-->
					<NewSignature v-if="card.permissionKey == 'p_btn_901_jingyingxiangmu_xiangqing_xinqian'" :permi="card.permissionKey" :hideList="hideList" :biProjectCode="biProjectCode" :updateDate="updateDate"></NewSignature>
					<!-- 收缴率 -->
					<CollectionRate v-if="card.permissionKey == 'p_btn_901_jingyingxiangmu_xiangqing_shoujiaolv'" :permi="card.permissionKey" :hideList="hideList" :biProjectCode="biProjectCode" :projectCode="projectCode" :updateDate="updateDate"> </CollectionRate>
					<!--欠款追缴-->
					<DebtInformation v-if="card.permissionKey == 'p_btn_901_jingyingxiangmu_xiangqing_qkqk'" :permi="card.permissionKey" :hideList="hideList" :biProjectCode="biProjectCode" :updateDate="updateDate"> </DebtInformation>
					<!--保证金押金-->
					<DepositAndCashPledge v-if="card.permissionKey == 'p_btn_901_jingyingxiangmu_xiangqing_bzjyj'" :permi="card.permissionKey" :hideList="hideList" :biProjectCode="biProjectCode" :updateDate="updateDate"></DepositAndCashPledge>
					<!--投资联营-->
					<InvestPool v-if="card.permissionKey == 'p_btn_901_jingyingxiangmu_xiangqing_tzly'" :permi="card.permissionKey" :hideList="hideList" :biProjectCode="biProjectCode" :updateDate="updateDate"></InvestPool>
					<!-- 资本化改造 -->
					<CapitalizationTransformation v-if="card.permissionKey == 'p_btn_901_jingyingxiangmu_xiangqing_zbhgz'" :permi="card.permissionKey" :hideList="hideList" :biProjectCode="biProjectCode" :updateDate="updateDate"></CapitalizationTransformation>
					<!-- 能耗分析 -->
					<EnergyCosts v-if="card.permissionKey == 'p_btn_901_jingyingxiangmu_xiangqing_nyf'" :permi="card.permissionKey" :hideList="hideList" :biProjectCode="biProjectCode" :updateDate="updateDate" />
					<!-- 预算对标 -->
					<BudgetcAhievement v-if="card.permissionKey == 'p_btn_901_jingyingxiangmu_xiangqing_ysdb'" :permi="card.permissionKey" :hideList="hideList" :biProjectCode="biProjectCode" :updateDate="updateDate"> </BudgetcAhievement>
					<!--两算一控-->
					<TwoControl v-if="card.permissionKey == 'p_btn_901_jingyingxiangmu_xiangqing_twoandone_control'" :permi="card.permissionKey" :hideList="hideList" :biProjectCode="biProjectCode" :updateDate="updateDate"></TwoControl>
					<!-- 费控分析 -->
					<CostControlAnalysis v-if="card.permissionKey == 'p_btn_901_jingyingsy_xiangqing_costanalysis'" :permi="card.permissionKey" :hideList="hideList" :biProjectCode="biProjectCode" :projectCode="projectCode" :updateDate="updateDate" />
					<!-- 费控对标 -->
					<CostControlStandard v-if="card.permissionKey == 'p_btn_901_jingyingxiangmu_xiangqing_costcontrol_standards'" :permi="card.permissionKey" :hideList="hideList" :biProjectCode="biProjectCode" :projectCode="projectCode" :updateDate="updateDate" />
					<!--整场测算-->
					<NewSigning v-if="card.permissionKey == 'p_btn_901_jingyingxiangmu_xiangqing_xinqianqingkuang'" :permi="card.permissionKey" :hideList="hideList" :biProjectCode="biProjectCode" :updateDate="updateDate"></NewSigning>
					<!--整场测算 新-->
					<WholeCalculation v-if="card.permissionKey == 'p_btn_901_jingyingshangye_zhengchangcesuan'" :permi="card.permissionKey" :hideList="hideList" :biProjectCode="biProjectCode" :updateDate="updateDate"></WholeCalculation>
					<!-- 两书对标 -->
					<LiangShu v-if="card.permissionKey == 'p_btn_901_jingyingxiangmu_xiangqing_lsdb'" :permi="card.permissionKey" :hideList="hideList" :biProjectCode="biProjectCode" :updateDate="updateDate"> </LiangShu>
					<!-- 巡检监控 -->
					<InspectionMonitoring v-if="card.permissionKey == 'p_btn_901_jingyingshangye_xunjianjiankong'" :permi="card.permissionKey" :hideList="hideList" :biProjectCode="biProjectCode" :projectCode="projectCode" :updateDate="updateDate" :projectName="biProjectName"> </InspectionMonitoring>
					<!-- 品牌监控 -->
					<NewOpenBrand v-if="card.permissionKey == 'p_btn_901_jingyingxiangmu_xiangqing_pinpaijiankong'" :permi="card.permissionKey" :hideList="hideList" :biProjectCode="biProjectCode" :projectCode="projectCode" :updateDate="updateDate"> </NewOpenBrand>
					<!-- 车场白名单 -->
					<CarParkWhiteList v-if="card.permissionKey == 'p_btn_901_shangye_chechangbaimingdan'" :permi="card.permissionKey" :hideList="hideList" :biProjectCode="biProjectCode" :projectCode="projectCode" :updateDate="updateDate"> </CarParkWhiteList>
					<!-- 车场异常抬杆 -->
					<AbnormalPoleLifting v-if="card.permissionKey == 'p_btn_901_shangye_chechangyichangtaigan'" :permi="card.permissionKey" :hideList="hideList" :biProjectCode="biProjectCode" :projectCode="projectCode" :updateDate="updateDate"> </AbnormalPoleLifting>
					<!-- 设备维保 -->
					<EquipmentMaintenance v-if="card.permissionKey == 'p_btn_901_shangye_shebeiweibao'" :permi="card.permissionKey" :hideList="hideList" :projectCode="projectCode" :updateDate="updateDate" />
					<!-- 财务-开办费 -->
					<FinanceKaiBanFei v-if="card.permissionKey == 'p_btn_901_shangye_xiangqing_startupexpenses'" :permi="card.permissionKey" :subjectType="4" :hideList="hideList" :biProjectCode="biProjectCode" :biProjectName="biProjectName" :yearmonth="yearmonth"> </FinanceKaiBanFei>
					<!-- 财务-利润率 -->
					<FinanceLiRunBiao v-if="card.permissionKey == 'p_btn_901_shangye_xiangqing_commercialprofit'" :permi="card.permissionKey" :subjectType="3" :hideList="hideList" :biProjectCode="biProjectCode" :biProjectName="biProjectName" :yearmonth="yearmonth"> </FinanceLiRunBiao>
					<!-- 财务-投入产出表 -->
					<FinanceTouRuChanChu v-if="card.permissionKey == 'p_btn_901_shangye_xiangqing_lnputoutput'" :permi="card.permissionKey" :subjectType="2" :hideList="hideList" :biProjectCode="biProjectCode" :biProjectName="biProjectName" :yearmonth="yearmonth"> </FinanceTouRuChanChu>
					<!-- 财务-资金来源占用表 -->
					<FinanceZiJinLaiYuanZhanYong v-if="card.permissionKey == 'p_btn_901_shangye_xiangqing_sourceandfunds'" :permi="card.permissionKey" :hideList="hideList" :biProjectCode="biProjectCode" :biProjectName="biProjectName" :yearmonth="yearmonth"> </FinanceZiJinLaiYuanZhanYong>
				</template>
			</div>
		</el-scrollbar>
		
		<DigitalMonthlyReport v-if="isShowDigitalMonthlyReport" :isFresh="isFresh" :biProjectCode="biProjectCode" :yearmonth="yearmonth" :tabPermi="tabPermi"></DigitalMonthlyReport>
		<ElectroMonitoring v-if="isShowElectroMonitoring" :projectCode="projectCode" :tabPermi="tabPermi" :updateDate="updateDate" :projectList="projectList" @changeProject="emitChangeProject"></ElectroMonitoring>
	</div>
</template>
<script setup>
	import DigitalMonthlyReport from '@/views/Manage/Business/DigitalMonthlyReport/digitalMonthlyReport';
	import ElectroMonitoring from '@/views/Energy/MonitorScreen/electroMonitoring.vue';
	
	// import BaseInfo from '@/views/Manage/Business/components/baseInfo';
	import SalesVolume from '@/views/Manage/Business/components/salesVolume';
	import PassengerFlow from '@/views/Manage/Business/components/passengerFlow';
	import RentalSituation from '@/views/Manage/Business/components/rentalSituation';
	import BrandAnalysis from '@/views/Manage/Business/components/brandAnalysis';
	import HouseCard from '@/views/Manage/Business/components/houseCard';
	import NewSigning from '@/views/Manage/Business/components/newSigning';
	import WholeCalculation from '@/views/Manage/Business/components/wholeCalculation';
	import NewSignature from '@/views/Manage/Business/components/newSignature';
	import WorkerOrder from '@/views/Manage/Business/components/workerOrder';
	import DebtInformation from '@/views/Manage/Business/components/debtInformation';
	import DepositAndCashPledge from '@/views/Manage/Business/components/depositAndCashPledge';
	import InvestPool from '@/views/Manage/Business/components/investPool';
	import CapitalizationTransformation from '@/views/Manage/Business/components/capitalizationTransformation';
	import BudgetcAhievement from '@/views/Manage/Business/components/budgetcAhievement';
	import LiangShu from '@/views/Manage/Business/components/liangShu';
	import TwoControl from '@/views/Manage/Business/components/twoControl';
	import EnergyCosts from '@/views/Manage/Business/components/energyCosts';
	import CostControlStandard from '@/views/Manage/Business/components/costControlStandard';
	import InspectionMonitoring from '@/views/Manage/Business/components/inspectionMonitoring';
	import LeaseAnalysis from '@/views/Manage/Business/components/leaseAnalysis';
	import NewOpenBrand from '@/views/Manage/Business/components/newOpenBrand';
	import CarParkWhiteList from '@/views/Manage/Business/components/carParkWhiteList';
	import AbnormalPoleLifting from '@/views/Manage/Business/components/abnormalPoleLifting';
	import EquipmentMaintenance from '@/views/Manage/Business/components/equipmentMaintenance';
	import CostControlAnalysis from '@/views/Manage/Business/components/costControlAnalysis.vue'
	import CollectionRate from '@/views/Manage/Business/components/collectionRate.vue'
	import FinanceKaiBanFei from '@/views/Manage/Business/components/financeKaiBanFei.vue'
	import FinanceLiRunBiao from '@/views/Manage/Business/components/financeLiRunBiao.vue'
	import FinanceTouRuChanChu from '@/views/Manage/Business/components/financeTouRuChanChu.vue'
	import FinanceZiJinLaiYuanZhanYong from '@/views/Manage/Business/components/financeZiJinLaiYuanZhanYong.vue'

	import dbPublicApi from '@/api/dbPublic';
	import { queryCardPermissionPcApi } from '@/api/dbPublic';

	import { ref } from 'vue';
	import { useRoute } from 'vue-router';
	const route = useRoute().query;
	let rid = ref(route.rid);
	let biProjectCode = ref(route.biProjectCode);
	const projectCode = ref(route.projectCode);
	const updateDate = route.updateDate; // 年月日
	const tabPermi = route.tabPermi;
	const groupList = ref([])
	const tabIndex = ref(0)
	const resourceList = ref([])

	const getGroup = async () => {
		await queryCardPermissionPcApi({biProjectCode: biProjectCode.value, pageKey: rid.value }).then(res => {
			if (res.data.code == 200) {
				groupList.value = res.data.data
				groupList.value[tabIndex.value] ? '' : tabIndex.value = 0
				resourceList.value = groupList.value[tabIndex.value] ? groupList.value[tabIndex.value].resourceList : groupList.value.length > 0 ? groupList.value[0].resourceList : []
			}
		});
	};

	let isShowDashboard = ref(true); // 驾驶舱卡片
	let isShowDigitalMonthlyReport = ref(false); // 数字月报
	let isShowElectroMonitoring = ref(false); // 监控大屏
	
	const changeTab = (index) => {
		tabIndex.value = index
		resourceList.value = groupList.value[index].resourceList
		isShowDashboard.value = groupList.value[index].key != 7 && groupList.value[index].key != 8
		isShowDigitalMonthlyReport.value = groupList.value[index].key == 7
		isShowElectroMonitoring.value = groupList.value[index].key == 8
	}

	let isShow = ref(false);
	let hideList = ref([]); // 卡片兼容 隐藏list设置为空 queryCardPermissionPcApi接口已过滤隐藏的卡片
	let projectList = ref([]);
	let biProjectName = ref('');

	const getList = () => {
		dbPublicApi.queryProjectPcApi({ dataTime: updateDate, resourceKey: tabPermi }).then(res => {
			if (res.data.code == 200) {
				projectList.value = res.data.data;
				let target = projectList.value.find(item => {
					return item.biProjectCode == biProjectCode.value;
				});
				biProjectName.value = target ? target.projectName : '';
			}
		});
	};

	const changeProject = async () => {
		isShow.value = false;
		getGroup()
		const index = projectList.value.findIndex(item => {
			return item.biProjectCode == biProjectCode.value;
		});
		projectCode.value = projectList.value[index].projectCode;
		biProjectName.value = projectList.value[index].projectName;
		isShow.value = true;

		// 如果是数字月报，则更新isFresh
		isShowDigitalMonthlyReport.value ? getTableData() : ''
	};

	const emitChangeProject = (data) => {
		biProjectCode.value = data.biProjectCode
		projectCode.value = data.projectCode
	}

	// --------- 数字月报相关 start ---------
	const isFresh = ref(new Date().getTime().toString());
	const yearmonth = ref()	
	// 获取商业数据更新日期 年月 用于数字月报筛选
	const queryDataUpdateTime = async () => {
		await dbPublicApi.queryMonthsTimeApi().then(res=>{
			let resData = res.data
			if(resData.code == 200){
				yearmonth.value = resData.data
			}
		})
	}
	const getTableData = () => {
		isFresh.value = new Date().getTime().toString();
	}
	// --------- 数字月报相关 end ---------

	const init = async () => {
		getGroup()
		await queryDataUpdateTime()
		isShow.value = false;
		getList();
		isShow.value = true;
	};
	init();

</script>

<style scoped lang="scss"></style>
